package momo.app.structure;

import momo.app.comms.RcvChannel;
import momo.app.comms.SendChannel;
import momo.app.config.AppConfig;

public class ChannelLink
{
	private Link<RcvChannel, SendChannel> link;
	
	public ChannelLink(RcvChannel rcvChannel, SendChannel sendChannel)
	{
		link = new Link<RcvChannel, SendChannel>(rcvChannel, sendChannel);
	}
	
	public RcvChannel getRcvChannel()
	{
		return link.getFirst();
	}
	
	public SendChannel getSendChannel()
	{
		return link.getSecond();
	}
	
	public void initCloseConnection()
	{
		Message closeMsg = new Message(
				Message.NO_FORWARD, 
				AppConfig.getInstance().getId(), 
				Message.CLOSE_CONNECTION, 
				AppConfig.getInstance().getMe().toString());
		getSendChannel().put(closeMsg.toString());
		
		closeRcvChannel();
	}
	
	public void closeRcvChannel()
	{
		getRcvChannel().stopRcving();
	}
	
	public void closeSendChannel()
	{
		getSendChannel().stopSending();
	}
	
	public void closeChannels()
	{
		closeRcvChannel();
		closeSendChannel();
	}
}//end of class ChannelLink
